import consola from 'consola'
import {features, head, mdPlugin, nav, sidebars} from './config'
import type {UserConfig} from 'vitepress'
import {languages} from './utils/lang'

const buildTransformers = () => {
    const transformer = () => {
        return {
            props: [],
            needRuntime: true,
        }
    }

    const transformers = {}
    const directives = [
        'infinite-scroll',
        'loading',
        'popover',
        'click-outside',
        'repeat-click',
        'trap-focus',
        'mousewheel',
        'resize',
    ]
    directives.forEach((k) => {
        transformers[k] = transformer
    })

    return transformers
}

consola.debug(`DOC_ENV: ${process.env.DOC_ENV}`)
const locales = {}
languages.forEach((lang) => {
    locales[`/${lang}`] = {
        label: lang,
        lang,
    }
})
export const config: UserConfig = {
    base: process.env.NODE_ENV !== 'production' ? '/' : '/ikun-plus/',
    title: 'Ikun Plus',
    description: '一个不止拥有普通组件的Vue3组件库',
    lastUpdated: true,
    themeConfig: {
        repo: 'ikun-plus',
        docsBranch: 'dev',
        docsDir: 'docs',
        editLinks: true,
        editLinkText: '去gitee上编辑此页面',
        lastUpdated: '最后更新',
        logo: '/images/ikun-plus-logo.svg',
        logoSmall: '/images/ikun-plus-logo-small.svg',
        agolia: {
            apiKey: '',
            appId: '',
        },
        sidebars,
        nav,
        features,
        head,
        langs: languages,
    },
    locales,
    markdown: {
        config: (md) => mdPlugin(md),
    },
    vue: {
        template: {
            ssr: true,
            compilerOptions: {
                directiveTransforms: buildTransformers(),
            },
        },
    },
}

export default config
